package com.ccsu.joysport.repository;
import com.ccsu.joysport.entity.StudentClub;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Optional;

public interface StudentClubRepository extends JpaRepository<StudentClub, Long> {
    List<StudentClub> findByStudentId(String studentId);
    List<StudentClub> findByClubId(String clubId);
    boolean existsByStudentId(String studentId);
    Optional<StudentClub> findByClubIdAndStudentId(String clubId, String studentId);
    void delete(StudentClub studentClub);

    @Query("SELECT COUNT(sc) FROM StudentClub sc WHERE sc.clubId = :clubId")
    int countMembersByClubId(@Param("clubId") String clubId);
}
